//
//  SendViewController.swift
//  Swift_SendMessage
//
//  Created by lanou on 15/11/25.
//  Copyright © 2015年 changfengZhang. All rights reserved.
//

import UIKit

//typealias和OC中的typedef一样
//格式：名字 =（参数）-> 返回值
typealias Closure = () -> Void

class SendViewController: UIViewController {

    @IBOutlet weak var textView: UITextView!
    
    var result : Closure!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    @IBAction func sendButtonClicked(sender: AnyObject) {
        
        let object = PFObject(className: "Yan30MyMessage")
        
        object.setObject(self.textView.text, forKey: "message")
        
        let (userName, userId) = UserManaged.defaultManager().findUserSince()
        
        object.setObject(userName, forKey: "userName")
        
        object.setObject(userId, forKey: "UID")
        
        object.saveInBackgroundWithBlock { (succeed, error) -> Void in
            
            if succeed {
                
                self.result()
                
                self.navigationController?.popViewControllerAnimated(true)
            }
           
        }
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
